/**
 * Created by ruby on 2/23/17.
 */

let EventProxy = require('eventproxy');
let fs = require('fs');

let ep = new EventProxy();

let files = [__dirname + '/1.txt', __dirname + '/2.txt'];
ep.after('got_files', files.length, function(content) {
  console.log(content); //content: ['abc', 'def']
});

for (let i=0; i<files.length; i++) {
  fs.readFile(files[i], 'utf-8', function (err, content) {
    ep.emit('got_files', content);
  });
}

ep.after('one', 3, function (one) {
  console.log(one);
  //console.log(two);
});
for (let i=0; i<3; i++) {
  ep.emit('one', i);
}
for (let i=0; i<3; i++) {
  ep.emit('two', i);
}